{extend name="public:layout" /}
{block name="title"}优惠套装{/block}
{block name="head"}{/block}
{block name="body"}
<div class="wrapper wrapper-content">
    <div class="ibox">
        <div class="ibox-title">
            <ol class="breadcrumb">
                <li><i class="fa fa-hand-o-right"></i> <a href="{:url('index')}"> 套装列表</a></li>
                <li class="active">编辑优惠套装</li>
            </ol>
        </div>
        <div class="ibox-content">
            <form method="post" class="form-horizontal" id="form">
                <div class="form-group">
                    <label class="col-sm-2 control-label Validform_label">套装名称</label>
                    <div class="col-sm-4">
                        <input type="text" class="form-control" placeholder="请输入套装名称" name="bl_name" value="{$info.bl_name}" datatype="*" />
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-2 control-label Validform_label">优惠套装价格</label>
                    <div class="col-sm-4">
                        <input type="text" class="form-control" readonly id="bl_discount_price" name="bl_discount_price" value="{$info.bl_discount_price}" datatype="*" />
                        <input type="hidden" name="total_simple_price" value="{$info.total_simple_price}" />
                        <p class="help-block">原价<span id="total_simple_price">0</span>元 (已添加搭配商品的默认价格总计)</p>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-2 control-label Validform_label">套装商品</label>
                    <div class="col-sm-10">
                        <div id="goodsList">
                            <table class="table table-bordered">
                                <thead>
                                <tr>
                                    <th width="50">#</th>
                                    <th width="300">商品名称</th>
                                    <th width="100">原价</th>
                                    <th width="100">优惠价格</th>
                                </tr>
                                </thead>
                                <tbody>
                                {volist name="info.item" id="vo"}
                                <tr>
                                    <td>
                                        <input type="hidden" name="sku_list[{$vo.sku_id}][bl_goods_id]" value="{$vo.bl_goods_id}" />
                                        <input type="hidden" name="sku_list[{$vo.sku_id}][simple_price]" value="{$vo.simple_price}" />
                                        {$vo.sku_id}
                                    </td>
                                    <td>
                                        <img src="{$vo.goods_thumb}" class="pull-left" style="width:32px;height:32px;margin:4px;" />
                                        {$vo.goods_name}
                                    </td>
                                    <td>{$vo.simple_price}</td>
                                    <td><input type="text" class="form-control bl_goods_price" onblur="calcPrice()" name="sku_list[{$vo.sku_id}][bl_goods_price]" value="{$vo.bl_goods_price}" /></td>
                                </tr>
                                {/volist}
                                </tbody>
                            </table>
                        </div>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-2 control-label Validform_label">运费承担</label>
                    <div class="col-sm-4">
                        <label class="radio-inline i-checks">
                            <input type="radio" name="bl_freight_choose" value="0" {eq name="info.bl_freight_choose" value="0"}checked{/eq} /> 卖家承担
                        </label>
                        <label class="radio-inline i-checks">
                            <input type="radio" name="bl_freight_choose" value="1" {eq name="info.bl_freight_choose" value="1"}checked{/eq} /> 买家承担
                        </label>
                    </div>
                </div>
                <div class="form-group" id="freight" {eq name="info.bl_freight_choose" value="0"}style="display:none;"{/eq}>
                    <label class="col-sm-2 control-label Validform_label">运费</label>
                    <div class="col-sm-4">
                        <input type="text" class="form-control" placeholder="请输入活动名称" name="bl_freight" value="{$info.bl_freight}" datatype="*" />
                    </div>
                </div>
                <div class="form-group">
                    <div class="col-sm-10 col-sm-offset-2">
                        <button class="btn btn-primary" type="button" id="btnSub">保存内容</button>
                        <a href="{:url('index')}" class="btn btn-white">取消</a>
                        <span id="validError"></span>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>
{/block}
{block name="script"}
<script type="text/javascript">
    $(function () {
        iCheck();
        calcPrice();
        $("input[name='bl_freight_choose']").on('ifChecked', function (event) {
            if($(this).val()==1){
                $('#freight').show();
            }else{
                $('#freight').hide();
            }
        });
        In('selectgoods');
        ajaxSubForm('#btnSub');
    })
    //计算价格
    function calcPrice(){
        var bl_discount_price=0;
        var total_simple_price=0;
        $("#goodsList tbody").find("tr").each(function(){
            var tdArr = $(this).children();
            var simple_price = tdArr.eq(2).text(); //原价
            var bl_goods_price = tdArr.eq(3).find('input').val(); //优惠价
            bl_discount_price += parseFloat(bl_goods_price);
            total_simple_price += parseFloat(simple_price);
        });
        $('#total_simple_price').text(total_simple_price);
        $("input[name='total_simple_price']").val(total_simple_price);
        $('#bl_discount_price').val(bl_discount_price);
    }
</script>
{/block}